#include <stdio.h>
#include <conio.h>
#include <windows.h>

#define M 3
#define N 4
#define P 5

void gotoxy(short x, short y);
void printBoard(int height,int width,int x,int y);
void inputMatrix(int a,int b,int x,int y);

int xMatrix[M][N];
int yMatrix[N][P];
int ansMatrix[M][P];

int main(void)
{
   int i,j;
   printBoard(M,N,1,1);
   printBoard(N,P,30,1);
   inputMatrix(M,N,2,2);
   inputMatrix(N,P,31,2);   
   
   for(j=0;j<P;j++)
   {
      for(i=0;i<M;i++)
      {
         ansMatrix[i][j] = (xMatrix[i][0]*yMatrix[0][j]) + 
                           (xMatrix[i][1]*yMatrix[1][j]) + 
                           (xMatrix[i][2]*yMatrix[2][j]) + 
                           (xMatrix[i][3]*yMatrix[3][j]);
      } 
      printf("\n");               
   }
   
   for(i=0;i<M;i++)
   {
      for(j=0;j<P;j++)
      {
         printf("%d\t",ansMatrix[i][j]);
      }
      printf("\n");
   }       
   getch(); 
   return 0;    
}

void inputMatrix(int a,int b,int x,int y)
{
   int i,j,temp;
   temp = x;
   for(i=0;i<a;i++)
   {
      for(j=0;j<b;j++)
      {
         if(a == M && b == N)
         {             
            gotoxy(x,y); scanf("%d",&xMatrix[i][j]);
         }
         else if(a == N && b == P)
         {
            gotoxy(x,y); scanf("%d",&yMatrix[i][j]);     
         }
         x+=5;    
      }
   x = temp;
   y+=2;                                
   }
        
}

void printBoard(int height,int width,int x,int y)
{
   if(height==M && width==N)
   {
      gotoxy(x,y);   printf("+----+----+----+----+");
      gotoxy(x,y+1); printf("|    |    |    |    |");
      gotoxy(x,y+2); printf("+----+----+----+----+");
      gotoxy(x,y+3); printf("|    |    |    |    |");
      gotoxy(x,y+4); printf("+----+----+----+----+");
      gotoxy(x,y+5); printf("|    |    |    |    |");
      gotoxy(x,y+6); printf("+----+----+----+----+");
   }
   else if(height==N && width==P)
   {
      gotoxy(x,y);   printf("+----+----+----+----+----+");
      gotoxy(x,y+1); printf("|    |    |    |    |    |");
      gotoxy(x,y+2); printf("+----+----+----+----+----+");
      gotoxy(x,y+3); printf("|    |    |    |    |    |");
      gotoxy(x,y+4); printf("+----+----+----+----+----+");
      gotoxy(x,y+5); printf("|    |    |    |    |    |");
      gotoxy(x,y+6); printf("+----+----+----+----+----+");
      gotoxy(x,y+7); printf("|    |    |    |    |    |");
      gotoxy(x,y+8); printf("+----+----+----+----+----+");             
   } 
}
void gotoxy(short x, short y) 
{
   COORD pos = {x, y};
   SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), pos);
}
